
#ifndef __STREAM_TO_DIRECTORY_H
#define __STREAM_TO_DIRECTORY_H

#include <vector>
#include <stack>
#include <stdint.h>
#include <apr-1/apr_pools.h>
#include <apr-1/apr_thread_proc.h>
#include "../db/NewKeyDB.h"

class StreamToDirectory
{
   public:
      enum currflagtype {   READING_FILE_NAME_SIZE   = 0,
                            READING_FILE_STREAM_SIZE = 1,
                            READING_NAME             = 2,
                            READING_STREAM           = 3   };
      StreamToDirectory(const char *directorypath, apr_pool_t *imp);
      ~StreamToDirectory();
      static int64_t readLogical64Bit(unsigned char *bytes);
      apr_off_t putNextBlock(char *blockbuffer, apr_off_t tsize);
      int recreateFile(char *blockbuffer, apr_off_t *maxlen);
   private:
      apr_pool_t *mp;
      char *directory_name;
      int currflag;
      int64_t currbytesthrough;
      int64_t nxtfilenamesze;
      unsigned char nxtfilenamesze_encoded[8];
      int64_t nxtfilestreamsze;
      unsigned char nxtfilestreamsze_encoded[8];
      char *nxtfilename;
};

#endif
